Visual Basic (Declaration) | |
---|---|
<SerializableAttribute()> Public Class WeakReference(Of T As Class) Inherits System.WeakReference |
C# | |
---|---|
[SerializableAttribute()] public class WeakReference<T> : System.WeakReference where T: class |
- T
Library/Library.Test/TestWeakReferenceT.cs
C# | Copy Code |
---|---|
string value1 = "Testing Value - 1"; object value2 = new MyObject(); Utils.WeakReference<string> r = new Utils.WeakReference<string>(value1); string tmp; Assert.IsTrue(r.TryGetTarget(out tmp) && tmp == value1); ((WeakReference)r).Target = value2; //incorrect type... Assert.IsFalse(r.IsAlive); Assert.IsNull(r.Target); Assert.IsFalse(r.TryGetTarget(out tmp)); Assert.IsTrue(ReferenceEquals(value2, ((WeakReference)r).Target)); |
VB.NET | Copy Code |
---|---|
Dim value1 As String = "Testing Value - 1" Dim value2 As Object = New MyObject() Dim r As New Utils.WeakReference(Of String)(value1) Dim tmp As String Assert.IsTrue(r.TryGetTarget(tmp) AndAlso tmp = value1) (DirectCast(r, WeakReference)).Target = value2 'incorrect type... Assert.IsFalse(r.IsAlive) Assert.IsNull(r.Target) Assert.IsFalse(r.TryGetTarget(tmp)) Assert.IsTrue(ReferenceEquals(value2, (DirectCast(r, WeakReference)).Target)) |
System.Object
System.WeakReference
CSharpTest.Net.Utils.WeakReference<T>
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
WeakReference<T> MembersCSharpTest.Net.Utils Namespace